package com.yugao.fintech.draper.security.customizer;

import com.yugao.fintech.draper.security.authentication.social.GiteeAuthenticationProvider;
import com.yugao.fintech.draper.security.authentication.password.DaoAuthenticationProvider;
import com.yugao.fintech.draper.security.authentication.password.PasswordAuthenticationProvider;
import com.yugao.fintech.draper.security.authentication.sms.SmsAuthenticationProvider;
import org.springframework.security.authentication.AuthenticationProvider;
import org.springframework.security.config.Customizer;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;

import java.util.Arrays;
import java.util.List;

public class AuthenticationProvidersCustomCustomizer implements Customizer<HttpSecurity> {

	/**
	 * @param httpSecurity the input argument
	 */
	@Override
	public void customize(HttpSecurity httpSecurity) {
		List<AuthenticationProvider> providerList = Arrays.asList(
				// 支持OAuth2GiteeAuthenticationToken类型的认证
				new GiteeAuthenticationProvider(httpSecurity),

				// 支持OAuth2ResourceOwnerSmsAuthenticationToken类型的认证
				new SmsAuthenticationProvider(httpSecurity),

				// 支持OAuth2ResourceOwnerPasswordAuthenticationToken类型的认证
				new PasswordAuthenticationProvider(httpSecurity),

				// 支持UsernamePasswordAuthenticationToken类型的认证
				new DaoAuthenticationProvider());

		providerList.forEach(httpSecurity::authenticationProvider);
	}

}
